const { execSync } = require('child_process');
const fs = require('fs');

try {
    // 读取 .nvmrc 文件中的版本号
    const version = fs.readFileSync('.nvmrc', 'utf8').trim();

    // 使用 nvm-windows 切换到指定版本
    console.log(`Switching to Node.js version: ${version}`);
    execSync(`nvm use ${version}`, { stdio: 'inherit' });

    // 通知父进程继续执行后续命令
    console.log('NodeSwitch2.cjs completed successfully.');
    process.exit(0);
} catch (error) {
    console.error(`Error switching Node.js version: ${error.message}`);
    console.error(`Error switching Node.js version: ${error.message}`);
    process.exit(1);
}
